<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
<!-- <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script> -->
<script src="./react.development.js"></script>
<script src="./react-dom.development.js"></script>
<script src="./babel.min.js"></script>
<script src="./prop-types.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
class LifyCycle extends React.Component{
  constructor(props){
    super(props);
    console.log('constructor()');
    this.state = {
      person:{
        name:'koke',
        age:39
      }
    }
  }
  //组件挂载之前执行
  componentWillMount(){
    setTimeout(()=>{
      this.setState({
        person:{
          name:'小孩',
          age:3
        }
      })
    },1000);
    console.log('componentWillMount()')
  }
  //组件挂载完毕
  componentDidMount(){
    this.intervalId = setInterval(()=>{
      console.log("interval()")
    },1000)
    console.log('componentDidMount()')
  }
  //组件将要更新
  componentWillUpdate(){
    console.log('componentWillUpdate()')
  }
  //组件更新完毕
  componentDidUpdate(){
    console.log('componentDidUpdate()')
  }
  //组件将要被卸载
  componentWillUnmount(){
    clearInterval(this.intervalId)
    console.log('componentWillUnmount()')
  }
  render(){
    console.log("render()");
    let {person} = this.state;
    return(
      <div>
        <span>{person.name}</span>
        <span>------</span>
        <span>{person.age}</span>
      </div>
    )
  }
}
ReactDOM.render(<LifyCycle />,document.getElementById('example'))
setTimeout(()=>{
  //卸载组件
  ReactDOM.unmountComponentAtNode(document.getElementById('example'))
},4000)
</script>
</body>
</html>